package net.zjitc.service.Impl;

import net.zjitc.dao.BookDao;
import net.zjitc.domain.Book;
import net.zjitc.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Collections;
import java.util.List;
@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BookDao bookDao;

    public List<Book> findAll() {
        return bookDao.findAll();
    }

    public boolean save(Book book) {
        return bookDao.insert(book)==1;
    }

    @Override
    public boolean delete(int id) {
        return bookDao.delete(id)==1;
    }

    @Override
    public Book findById(int id) {
        return bookDao.findById(id);
    }

    @Override
    public boolean update(Book book) {
        return bookDao.update(book)==1;
    }

    @Override
    public List<Book> findByCondition(Book book) {
        Book book1 = new Book();
        book1.setName("%"+book.getName()+"%");
        book1.setIsbn("%"+book.getIsbn()+"%");
        book1.setAuthor("%"+book.getAuthor()+"%");
        return bookDao.findByCondition(book1);
    }
}
